package com.caiyouxi.partner.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.partner.mapper.ChannelVersionMapper;
import com.caiyouxi.partner.model.ChannelVersionBean;
import com.caiyouxi.partner.service.ChannelVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ChannelVersionServiceImpl extends BaseService implements ChannelVersionService {
    @Autowired
    private ChannelVersionMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData select_version(ChannelVersionBean bean) {
        return success(mapper.select_channel_version(bean.getId()));
    }

    @Override
    public ResData get_version_list(ChannelVersionBean bean) {
        Integer pageSize = Integer.parseInt(redisService.get("sys.pagesize").toString());//后台获取默认每页多少调数据
        Integer p = bean.getPage_size();                            //查看前台是否给了每页几条数据
        if(p == 0 || p == null){
            p = pageSize;                                           //如果没给数据，则取默认数据
        }
        bean.setPage_size(p);
        QueryParams pageList = new QueryParams();
        List list = mapper.get_channel_version_list(bean);
        pageList.setList(list);
        pageList.setTotal(mapper.get_count(bean));
        pageList.setPage_size(bean.getPage_size());
        return success(pageList);
    }

    @Override
    public ResData add_version(ChannelVersionBean bean) {
        return success(mapper.add_channel_version(bean));
    }

    @Override
    public ResData update_version(ChannelVersionBean bean) {
        return success(mapper.update_channel_version(bean));
    }

    @Override
    public ResData delete_version(ChannelVersionBean bean) {
        return success(mapper.delete_channel_version(bean));
    }
}
